from django_redis import get_redis_connection


class MyRedis:
    def __init__(self):
        self.redis = get_redis_connection(alias='default')

    def set_str(self, key, value, time):
        return self.redis.setex(key, time, value)

    def get_str(self, key):
        val = self.redis.get(key)
        if val:
            return val.decode('utf-8')
        else:
            return None

    def hot_add(self, key, word):
        return self.redis.zincrby(key, 1, word)

    def hot_get(self, key, num):
        return self.redis.zrevrange(key, 0, num)

    def set_string(self, key, value):
        return self.redis.set(key, value)

    def del_string(self, key):
        return self.redis.delete(key)


redis_toll = MyRedis()
